<template>
  <div class="bar-container">
    <el-card>
      <div id="bar" :style="{width: width, height: height}"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: 'Bar',
  props:{
    height:{
      type: String,
      default: '200px'
    },
    width:{
      type: String,
      default: '200px'
    }
  },
  mounted () {
    this.$nextTick(() =>{
      this.initCharts()
    })
  },
  methods: {
    initCharts(){
      const charts = echarts.init(document.getElementById('bar'))
      const option = {
        title:{
          text: '柱状图',
          textStyle:{
            fontWeight: 400,
          }
        },
        legend: {
          top: 20,
        },
        tooltip: {},
        dataset: {
          source: [
            ['product', '2015', '2016', '2017'],
            ['Matcha', 43.3, 85.8, 93.7],
            ['Milk', 83.1, 73.4, 55.1],
            ['Cheese', 86.4, 65.2, 82.5],
            ['Walnut', 72.4, 53.9, 39.1]
          ]
        },
        xAxis: { type: 'category' },
        yAxis: {},
        // Declare several bar series, each will be mapped
        // to a column of dataset.source by default.
        series: [{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]
      };
      charts.setOption(option);
    },
  }
}
</script>

<style scoped>

</style>
